package setting

import (
	"context"
	"strings"

	"mall/service/forum/rpc/internal/svc"
	"mall/service/forum/rpc/types/forum"

	"github.com/zeromicro/go-zero/core/logx"
)

type BackendGetPageSettingLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBackendGetPageSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BackendGetPageSettingLogic {
	return &BackendGetPageSettingLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BackendGetPageSettingLogic) BackendGetPageSetting(in *forum.BackendGetPageSettingReq) (*forum.BaseResp, error) {
	if in.Key != nil {
		setting, err := l.svcCtx.User.GetPageSetting(l.ctx, nil, strings.TrimSpace(*in.Key))
		if err != nil {
			return nil, err
		}

		return &forum.BaseResp{
			Msg: setting,
		}, nil
	}

	return &forum.BaseResp{}, nil
}
